"""
    用于标注团队模块的功能操作，如添加用户，新建团队，编辑团队，成员管理
"""
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from automatic import page
from automatic.base.base import Base
from automatic.base.get_logger import GetLogger
from selenium.webdriver.support import expected_conditions as EC

# 获取log日志器
log = GetLogger().get_logger()

class PageTaskTeam(Base):
    #点击用户管理
    def page_click_user_management(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_user_management))
        self.base_click(page.task_user_management)

    #点击运营人员
    def page_click_operational_members(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_operational_members))
        self.base_click(page.task_operational_members)

    #点击标注团队
    def page_click_all_team(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_all_team))
        self.base_click(page.task_all_team)

    #点击添加用户
    def page_click_add_user(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_add_user))
        self.base_click(page.task_add_user)

    #输入用户名
    def page_input_username(self,username):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_username,username))
        self.base_input(page.task_username,username)

    #输入密码
    def page_input_password(self,password):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_password,password))
        self.base_input(page.task_password,password)

    #再次输入密码
    def page_input_password2(self,password2):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_password2, password2))
        self.base_input(page.task_password2,password2)

    #点击标准团队选择框
    def page_click_team_frame(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_team_frame))
        self.base_click(page.task_team_frame)

    #选择标注团队
    def page_select_team(self,team_name):
        # 动态构造团队选项的定位器
        team_locator = (page.task_select_team[0], page.task_select_team[1].format(team_name))
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(team_locator))
        self.base_click(team_locator)

    #不输入任意信息，点确定，获得错误信息
    def page_get_add_err_info(self,empty_info):
        err_info=(page.task_add_err_info[0],page.task_add_err_info[1].format(empty_info))
        log.info("[page_task_team]:正在获取{}元素的文本信息".format(err_info))
        return self.base_get_text(err_info)

    #点击取消按钮
    def page_click_reject(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_add_reject))
        self.base_click(page.task_add_reject)

    #点击确定按钮
    def page_click_confirm(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_add_confirm))
        self.base_click(page.task_add_confirm)

    #点击新建团队
    def page_click_add_team(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_add_team))
        self.base_click(page.task_add_team)

    #不输入团队名称点击确定，获取错误信息
    def page_get_err_info(self):
        log.info("[page_task_team]:正在获取{}元素的文本信息".format(page.task_team_err_info))
        return self.base_get_text(page.task_team_err_info)

    #输入团队名称
    def page_input_team_name(self,name):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_team_name,name))
        self.base_input(page.task_team_name,name)

    #输入联系人
    def page_input_owner(self,owner_name):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_team_owner, owner_name))
        self.base_input(page.task_team_owner,owner_name)

    #输入联系人电话
    def page_input_owner_phone(self,owner_phone):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_team_owner_phone, owner_phone))
        self.base_input(page.task_team_owner_phone,owner_phone)

    #获取错误手机号的信息:page_get_err_info

    #点击取消：page_click_reject

    #点击第n行的编辑按钮
    def page_click_edit(self,row,button_number):
        # 动态构造团队选项的定位器
        button = (page.task_team_select[0], page.task_team_select[1].format(row,button_number))
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(button))
        self.base_click(button)

    #输入团队名称:page_input_team_name

    #输入联系人:page_input_owner

    #输入联系人电话:page_input_owner_phone

    #点击确定按钮:page_click_confirm

    #获取提交成功的提示信息
    def page_get_info(self):
        log.info("[page_task_team]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    #第n行的成员管理按钮:page_click_edit

    #点击搜索框,输入成员名称
    def page_input_search_name(self,username):
        log.info("[page_task_team]:正在对{}元素进行输入{}操作".format(page.task_team_name, username))
        self.base_input(page.task_team_name,username)

    #点击搜索按钮:page_click_add_team

    #点击邀请成员按钮:page_click_confirm

    #点击复制链接
    def page_click_link(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_invite_link))
        self.base_click(page.task_invite_link)

    #获取复制成功信息:page_get_info

    #点击重新生成链接
    def page_click_refresh_link(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_refresh_link))
        self.base_click(page.task_refresh_link)

    #关闭邀请成员页面
    def page_click_close_invite(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_close_invite))
        self.base_click(page.task_close_invite)

    #点击移除成员按钮
    def page_click_remove_member(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_remove_member))
        self.base_click(page.task_remove_member)

    #点击确定按钮
    def page_click_remove_confirm(self):
        log.info("[page_task_team]:正在对{}元素进行点击操作".format(page.task_remove_member_confirm))
        self.base_click(page.task_remove_member_confirm)


    #封装添加用户操作
    def add_user(self,username,password,password2,team_name):
        self.page_click_add_user()
        time.sleep(2)
        self.page_input_username(username)
        time.sleep(2)
        self.page_input_password(password)
        time.sleep(2)
        self.page_input_password2(password2)
        time.sleep(2)
        self.page_click_team_frame()
        time.sleep(2)
        self.page_select_team(team_name)
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(2)

    #封装添加用户成功操作
    def add_user_success(self,username='cxx3',password='123456',password2='123456',team_name='标注小组1'):
        self.page_click_add_user()
        time.sleep(2)
        self.page_input_username(username)
        time.sleep(2)
        self.page_input_password(password)
        time.sleep(2)
        self.page_input_password2(password2)
        time.sleep(2)
        self.page_click_team_frame()
        time.sleep(2)
        self.page_select_team(team_name)
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(1)

    #封装新建团队操作
    def add_team(self,team_name,owner_name,owner_phone):
        self.page_click_add_team()
        time.sleep(2)
        self.page_input_team_name(team_name)
        time.sleep(2)
        self.page_input_owner(owner_name)
        time.sleep(2)
        self.page_input_owner_phone(owner_phone)
        time.sleep(2)
        self.page_click_reject()
        time.sleep(2)

    #封装编辑团队操作
    def edit_team(self,row,button_number,team_name,owner_name,owner_phone):
        self.page_click_edit(row,button_number)
        time.sleep(2)
        self.page_input_team_name(team_name)
        time.sleep(2)
        self.page_input_owner(owner_name)
        time.sleep(2)
        self.page_input_owner_phone(owner_phone)
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(2)

    #封装编辑团队成功操作
    def edit_team_success(self,team_name='edit_name',owner_name='edit_owner_name',owner_phone='13100000000'):
        self.page_click_edit(1,1)
        time.sleep(2)
        self.page_input_team_name(team_name)
        time.sleep(2)
        self.page_input_owner(owner_name)
        time.sleep(2)
        self.page_input_owner_phone(owner_phone)
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(2)

    #封装成员管理操作
    def edit_user_member(self,username):
        self.page_click_edit(1,2)
        time.sleep(2)
        self.page_input_search_name(username)
        time.sleep(2)
        self.page_click_add_team()
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(2)
        self.page_click_link()
        time.sleep(1)